package config

import (
	"database/sql"
)

/*
掉绑比例配置
*/
type CfgDisableBindItem struct {
	CfgInviteBase    int `json:"InviteCounts" db:"InviteCounts" cbor:"InviteCounts"`
	CfgInviteCount   int `json:"DisableBindRate" db:"DisableBindRate" cbor:"DisableBindRate"`
	CfgDisbindCounts int `json:"max_disableBind" db:"max_disableBind" cbor:"max_disableBind"`
	OperatorId       int `json:"operator_id" db:"operator_id" cbor:"operator_id"`
}
type CsDisableBindCfg struct{}

var CfgDisableBindList []CfgDisableBindItem

func (that *CsDisableBindCfg) GetCfg() []CfgDisableBindItem {
	return CfgDisableBindList
}

func (that *CsDisableBindCfg) removeAllCfg() {
	CfgDisableBindList = []CfgDisableBindItem{}
}

func DisableBindCfgRemove() {
	CfgDisableBindList = []CfgDisableBindItem{}
}

func DisableBindCfgSetRow(rows *sql.Rows) {
	var tVal CfgDisableBindItem
	var err error
	err = rows.Scan(&tVal.CfgInviteBase, &tVal.CfgInviteCount, &tVal.CfgDisbindCounts, &tVal.OperatorId)
	if err == nil {
		CfgDisableBindList = append(CfgDisableBindList, tVal)
	}
}

type UserDisableBindItem struct {
	CfgInviteBase    int `json:"InviteCounts" db:"InviteCounts" cbor:"InviteCounts"`          //配置区间的起始人数
	CfgInviteCount   int `json:"DisableBindRate" db:"DisableBindRate" cbor:"DisableBindRate"` //配置区间的邀请人数
	CfgDisbindCounts int `json:"max_disableBind" db:"max_disableBind" cbor:"max_disableBind"` //配置区间的掉绑人数
}

type UnbindItemSlice []UserDisableBindItem

func (p UnbindItemSlice) Len() int           { return len(p) }
func (p UnbindItemSlice) Less(i, j int) bool { return p[i].CfgInviteBase > p[j].CfgInviteBase }
func (p UnbindItemSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
